// 导入路由
import VueRouter from 'vue-router'

// 注册路由
import Vue from 'vue'
Vue.use(VueRouter)

// 创建路由实例
const router = new VueRouter({
  routes: [{
    path: '/',
    redirect: '/home'
  }, {
    path: '/home',
    component: () => '@/views/HomeView',
    meta: { title: '首页' }
  }, {
    path: '/search',
    component: () => '@/views/SearchView',
    meta: { title: '搜索' }
  }, {
    path: '/play',
    component: () => '@/views/PlayView',
    meta: { title: '播放' }
  }, {
    path: '*',
    component: () => '@/views/NotFound',
    meta: { title: '404 Not found' }
  }]
})

// 全局路由守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) document.title = to.meta.title
  next()
})

// 导出路由
export default router
